package chap2_6;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author https://gitee.com/W_Jun
 * @version 1.0
 * @date 2021-11-26 21:47
 * @Description
 */
public class CopyTxtDemo {
    public static void main(String[] args) {
        //根据数据源创建字节输入流对象
        //根据目的地创建字节输出流对象
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream("D:\\project\\hello.txt");
            fos = new FileOutputStream("chapter02-字节流\\hello.txt");
            //读写数据
            int by;
            while ((by = fis.read()) != -1) {
                fos.write(by);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
